package com.hsmpay.yl8583.service;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import org.apache.commons.lang.StringUtils;
import org.springframework.context.ApplicationContext;
import com.hsmpay.yl8583.utils.Field;
import com.hsmpay.yl8583.utils.Package64;
import com.hsmpay.yl8583.utils.PackageUtil;
import com.hsmpay.yl8583.utils.SpringUtil;
import com.hsmpay.yl8583.utils.TestDes;
import com.hsmpay.utils.DesUtil;
import com.hsmpay.utils.TimeUtils;
import com.hsmpay.utils.WriteFile;
import com.hsmpay.utils.system.ConConfig;
/**
 * EBC 代收
 * 1、没有用header  为了兼容在解析的时候  添加了header 
 * 2、在签到的时候 有不同的规则 pinKey16+8+macKey16+8+trkKey16+8
 * @author ylz
 */
public class EBCSocketToBoss {
	private ApplicationContext act;
	static WriteFile wf = new WriteFile("ds_EBC");
	public static String debug = ConConfig.getAttribute("EBC_DAISHOU_DEBUG_STATUS");
	
	//宁波银联生产平台
	static String ipAdd="222.128.22.116";
	static String IPort="8001";
	String itimeout="60000";
	
	String ShopCode = "600000000000001";//商户号
	String PosNo = "11111111";			//终端号
	
	String tpdu = "6000030000";
	String header = "603100310001";
	String batch = "000001"; 			 // 批次号
	String serialNumber = "000002"; 	 // 系统跟踪号(POS中心流水号)
	String operator="001";				 //操作员
	String bit32="00000000";			//受理方标识码(1-4位:机构代码，5-8位:地区代码)
	String bit62="0000000000000000000000000000000";			//订单支付信息(订单号n20+手机号n11)
	//费率密文密码密钥
	//static String PinKey="E53124013FF3617C6344A9D08591208A";
	//费率密文报文密钥
	//static String MacKey="E0974018645EBBBFE0974018645EBBBF";
	
	//封顶密文密码密钥
	String PinKey="41EB108FCAFD0D6010D94DA377CADDF8";
	//封顶密文报文密钥
	String MacKey="09CA88DBA570F640134C098085A6C733";
	//磁道密钥
	String trkKey="EF29250D6EC8839D19F76ECD13B57F19";
	//母POS密钥
	String MasterKey="44444444444444444444444444444444";
	
	byte[] bitmap = new byte[8];
	
	static{
		if("1".equals(debug)){
			ipAdd="114.255.132.193";//
			IPort="6000";
		}
	}
	
	/**
	 * 构造函数
	 * @param ShopCode
	 * @param PosNo
	 * @param batch
	 * @param MasterKey
	 * @param PinKey
	 * @param MacKey
	 * @param trkKey
	 */
	public EBCSocketToBoss(String ShopCode,String PosNo,String batch,String MasterKey,String PinKey,String MacKey,String trkKey){
		this.ShopCode = ShopCode;
		this.PosNo = PosNo;
		
		this.batch = batch;
		this.MasterKey = MasterKey;
        System.out.println("EBC收款MasterKey："+MasterKey);
		this.PinKey = PinKey;
        System.out.println("EBC收款PinKey："+PinKey);
		this.MacKey = MacKey;
        System.out.println("EBC收款MacKey："+MacKey);
		this.trkKey = trkKey;
        System.out.println("EBC收款trkKey："+trkKey);
		if(null != trkKey && StringUtils.isNotEmpty(trkKey.trim()))
			this.trkKey=DesUtil.decode3DES(trkKey, MasterKey);
		if(null != batch && StringUtils.isEmpty(batch.trim())){
			this.batch = "000001";
		}
		
		act = SpringUtil.getApplicationContext();
		wf.log("tpdu:" + this.tpdu, "调试");
		wf.log("ShopCode(商户号):" + this.ShopCode, "调试");
		wf.log("PosNo(终端号):" + this.PosNo, "调试");
		wf.log("batch(批次号):" + this.batch, "调试");
		wf.log("MasterKey:" + this.MasterKey, "调试");
		wf.log("PinKey:" + this.PinKey, "调试");
		wf.log("MacKey:" + this.MacKey, "调试");
		wf.log("trkKey:" + this.trkKey,"调试");
	}
	

	/**
	 * 通信检测(0000)
	 * 
	 * @return 是否正常
	 */
	public String detection(byte[] sendStr) {
		SendSocket send = new SendSocket(ipAdd, IPort, itimeout,wf);
		return send.detection(sendStr);
	}

	public String AddSerialNumber(String SerialNumber) {
		int OldLen = 6;
		String NewStr = (Integer.parseInt(SerialNumber) + 1) + "";
		int NewLen = NewStr.length();
		if (NewLen == 7) {
			NewStr = "000000";
			NewLen = 6;
		}
		for (int i = 0; i < (OldLen - NewLen); i++) {
			NewStr = "0" + NewStr;
		}
		return NewStr;
	}

	public String unAddSerialNumber(String SerialNumber) {
		int OldLen = 6;
		String NewStr = "";
		if (SerialNumber.equals("000000")) {
			NewStr = "999999";
		} else {
			NewStr = (Integer.parseInt(SerialNumber) - 1) + "";
		}
		int NewLen = NewStr.length();
		for (int i = 0; i < (OldLen - NewLen); i++) {
			NewStr = "0" + NewStr;
		}
		return NewStr;
	}

	// 将字符串按指定长度返回,不足位数在前面加0。
	public String GetNewStr(String str, int len) {
		String NewStr = "";
		for (int i = 0; i < len - str.length(); i++) {
			NewStr += "0";
		}
		NewStr += str;
		return NewStr;
	}
	//获取字符串字节长度(双字节长度为2,单字节长度为1)
	public int strlen(String str){ 
		int len=0;
	    try {
			len= (new String(str.getBytes("GBK"), "ISO-8859-1")).length();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} 
		return len;
	}
	//获取字符串中单双字节的个数并以";"分隔返回。
	public String getCharString(String inputText)
	{
		int count = 0; 
		int chCharCount = 0;
		int dconut=0;
		char[] charArray = inputText.toCharArray(); 
		for (int i = 0; i < charArray.length; i++) { 
			char cn = charArray[i]; 
			byte[] bytes = (String.valueOf(cn)).getBytes(); 
			if (bytes.length == 1) { //单字节字符
				dconut++;
				//英文字符 
				//int ascii = bytes[0]; 
			}else if (bytes.length == 2) { //双字节字符 
				count++; 
				int hightByte = 256 + bytes[0]; 
				int lowByte = 256 + bytes[1]; 
				int ascii = (256 * hightByte + lowByte) - 256 * 256; 
				if (ascii >= -20319 && ascii < -10247) { //中文字符 
					chCharCount++; 
				} 
			} 
		} 
		System.out.println( "共有 " + dconut + " 个单字节字符! "); 
		System.out.println( "共有 " + count + " 个双字节字符! "); 
		System.out.println( "共有 " + chCharCount + " 汉字! "); 
		return dconut+";"+count;
	}
	/**
	 * 终端签到
	 * 
	 * @return 批次号
	 * @throws Exception
	 */
	public String Login0800(String serialNumber) throws Exception {
		try{
			String LoginMsg = "0";
			String TYPE_ID = "0800";
			wf.log("-------------------请求包域值信息-------------------",	"调试");
			Package64 pk = new Package64();
			pk.setTpdu(PackageUtil.hexStringToByte(this.tpdu));
			pk.setHeader(PackageUtil.hexStringToByte(""));
			pk.setMessagetype(PackageUtil.hexStringToByte(TYPE_ID));
			wf.log("[tpdu]=" + this.tpdu, "调试");
			wf.log("[header]=" + this.header, "调试");
			wf.log("[messagetype]=" + TYPE_ID, "调试");
			// 11、41、42、60、63
			String str = "bit11,bit32,bit41,bit42,bit60,bit63";
			for (String one : str.split(",")) {
				Field filed = (Field) act.getBean(one);
				if(one.equals("bit11"))
				{
					filed.valueof(serialNumber);
				}else if (one.equals("bit32")) {
					filed.valueof("00000000001");
				}else if (one.equals("bit41")) {
					filed.valueof(this.PosNo);
				}else if (one.equals("bit42")) {
					filed.valueof(this.ShopCode);
				} else if (one.equals("bit60")) {
					filed.valueof("00" + this.batch + "003");
				} else if (one.equals("bit63")) {
					filed.valueof(PackageUtil.getCnASCII("0"+this.operator));
				}
				pk.getData().put(filed.getFiledNumber(), filed);
			}
			this.bitmap = Package64.CreateBitMap(pk.getData().keySet());
			wf.log("[bitmap]=" + PackageUtil.byte2hex(this.bitmap),"调试");
			for (Integer one : pk.getData().keySet()) {
				wf.log("bit" + one + ":"+ PackageUtil.byte2hex(pk.getData().get(one).toByte()),"调试");
			}
			wf.log("----------------------------------------------------", "调试");
			pk.setBitmap(this.bitmap);
			byte[] pk_byteArray = pk.package64();
			ByteBuffer buff = ByteBuffer.allocate(pk_byteArray.length + 2);
			buff.putShort((short) pk_byteArray.length);
			buff.put(pk_byteArray);
	
	
			wf.log("请求包:长度 " + pk_byteArray.length + " 数据 "	+ PackageUtil.byte2hex(buff.array()), "调试");
			wf.log("", "调试");
			LoginMsg = detection(buff.array());
			if ((!LoginMsg.equals("-1")) && (!LoginMsg.equals("")))
			{
				String tpdu=LoginMsg.substring(0, 10);
				String Msg=LoginMsg.substring(10);
				LoginMsg=tpdu+header+Msg;
			}
			wf.log("响应包:长度 " + LoginMsg.length() / 2 + " 数据 "+ LoginMsg, "调试");
			if ((!LoginMsg.equals("-1")) && (!LoginMsg.equals(""))) {
				LoginMsg = "0"+ Package64.UnPackage(PackageUtil.hexStringToByte(LoginMsg), "39,60,62",wf);
				
				String startMsg = LoginMsg.substring(0, LoginMsg.lastIndexOf("_"));
				String bit62 = LoginMsg.substring(LoginMsg.lastIndexOf("_")+1);
				bit62 = PackageUtil.toStringHex(bit62);//转为BCD 16进制
				bit62 = bit62.substring(0, 32)+"_"+bit62.substring(48,80)+"_"+bit62.substring(96,128);
				LoginMsg = startMsg+"_"+bit62;
			} else {
				return "-1_";
			}
			wf.log("银联签到返回数据:" + LoginMsg, "调试");
			return LoginMsg;
		}catch(Exception e){
			throw e;
		}
	}
	/**
	 * 银行卡余额查询
	 * 
	 * @param trk2
	 *            二磁道数据
	 * @param trk3
	 *            二磁道数据
	 * @param des_pin
	 *            卡交易密码
	 * 
	 * @return 订单信息
	 * @throws Exception
	 */
	public String Query(String trk2, String trk3, String pin,String accountNumber,String serialNumber,String bit23,String bit55,String bit14)throws Exception {
		try{
			String des_pin=TestDes.MakeDesPin(accountNumber, pin, PinKey,MasterKey);
			
			String QueryMsg = "";
			String TYPE_ID = "0200";
			wf.log("-------------------请求包域值信息-------------------","调试");
			Package64 pk = new Package64();
			pk.setTpdu(PackageUtil.hexStringToByte(this.tpdu));
			pk.setHeader(PackageUtil.hexStringToByte(""));
			pk.setMessagetype(PackageUtil.hexStringToByte(TYPE_ID));
			wf.log("[tpdu]=" + this.tpdu, "调试");
			wf.log("[header]=" + this.header, "调试");
			wf.log("[messagetype]=" + TYPE_ID, "调试");
			// 3、11、22、25、26、35、36、41、42、49、52、53、60、64
			String str = "bit3,bit11,bit22,bit25,bit26,bit35,bit36,bit41,bit42,bit49,bit52,bit53,bit60,bit64";
			String temp52=",bit52";
			String temp35=",bit35";
			String temp36=",bit36";
			
			String temp23=",bit23";
			String temp55=",bit55";
			String temp14=",bit14";
			//String Pan="";
			if("".equals(trk2.trim()))
			{
				temp35="";
			}else{
				//Pan=trk2.split("d")[0];
				trk2=DesUtil.newEncryptStanderTranck(trkKey, trk2).substring(2);
				System.out.println("密文trk2:"+trk2);
			}
			if("".equals(trk3.trim()))
			{
				temp36="";
			}else{
				trk3=DesUtil.newEncryptStanderTranck(trkKey, trk3).substring(2);
			}
			if("".equals(des_pin.trim()))
			{
				temp52="";
			}
			if("".equals(bit23.trim()))
			{
				temp23="";
			}
			if("".equals(bit55.trim()))
			{
				temp55="";
			}
			if("".equals(bit14.trim()))
			{
				temp14="";
			}
			
			str="bit2,bit3,bit11"+temp14+",bit22"+temp23+",bit25,bit26"+temp35+temp36+",bit41,bit42,bit49"+temp52+",bit53"+temp55+",bit60,bit64";
			for (String one : str.split(",")) {
				Field filed = (Field) act.getBean(one);
				if (one.equals("bit2")) {
					filed.valueof(accountNumber);
				} else if (one.equals("bit3")) {
					filed.valueof("311111");
				} else if (one.equals("bit11")) {
					filed.valueof(serialNumber);
				} else if (one.equals("bit14")) {
					filed.valueof(bit14);
				} else if (one.equals("bit22")) {
					if("".equals(bit55.trim()))
					{
						filed.valueof("021");
					}else{
						filed.valueof("051");
					}
				} else if (one.equals("bit23")) {
					filed.valueof(bit23);
				} else if (one.equals("bit25")) {
					filed.valueof("00");
				} else if (one.equals("bit26")) {
					filed.valueof("06");
				} else if (one.equals("bit35")) {
					filed.valueof(trk2);
				} else if (one.equals("bit36")) {
					filed.valueof(trk3);
				} else if (one.equals("bit41")) {
					filed.valueof(this.PosNo);
				} else if (one.equals("bit42")) {
					filed.valueof(this.ShopCode);
				} else if (one.equals("bit49")) {
					filed.valueof("156");
				} else if (one.equals("bit52")) {
					byte[] tmp = PackageUtil.hexStringToByte(des_pin);
					filed.valueof(tmp);
				}else if (one.equals("bit53")) {
					filed.valueof("2600000000000000");
				}  else if (one.equals("bit55")) {
					filed.valueof(bit55);
				} else if (one.equals("bit60")) {
					if("".equals(bit55.trim()))
					{
						filed.valueof("01" + this.batch);
					}else{
						filed.valueof("01" + this.batch+"00050");
					}
				} else if (one.equals("bit64")) {
					byte[] tmp = PackageUtil.hexStringToByte("4632354542374636");
					filed.valueof(tmp);
				}
				pk.getData().put(filed.getFiledNumber(), filed);
			}
	
			this.bitmap = Package64.CreateBitMap(pk.getData().keySet());
			wf.log("[bitmap]=" + PackageUtil.byte2hex(this.bitmap),"调试");
	
			pk.setBitmap(this.bitmap);
	
			String tranMsg = PackageUtil.byte2hex(pk.getMessagetype())+ PackageUtil.byte2hex(pk.getBitmap());
			for (Integer one : pk.getData().keySet()) {
				if (one != 64) {
					String bitval = PackageUtil.byte2hex(pk.getData().get(one).toByte());
					tranMsg += bitval;
					wf.log("bit" + one + ":" + bitval, "调试");
				}
			}
			String macstr="";
			macstr=TestDes.MakeECBMac(MacKey, tranMsg,MasterKey);
			System.out.println("tranMsg:" + tranMsg);
			System.out.println("bit64:" + macstr);
			wf.log("bit64:" + macstr, "调试");
	
			Field filed = (Field) act.getBean("bit64");
			byte[] tmp = PackageUtil.hexStringToByte(macstr);
			filed.valueof(tmp);
			pk.getData().put(filed.getFiledNumber(), filed);
			byte[] pk_byteArray = pk.package64();
			ByteBuffer buff = ByteBuffer.allocate(pk_byteArray.length + 2);
			System.out.println("pk_byteArray length: " + pk_byteArray.length);
			buff.putShort((short) pk_byteArray.length);
			buff.put(pk_byteArray);
			System.out.println(PackageUtil.byte2hex(buff.array()));
			wf.log(	"----------------------------------------------------", "调试");
			wf.log("请求包:长度 " + pk_byteArray.length + " 数据 "	+ PackageUtil.byte2hex(buff.array()), "调试");
			wf.log("", "调试");
			QueryMsg = detection(buff.array());
			if ((!QueryMsg.equals("-1")) && (!QueryMsg.equals("")))
			{
				String tpdu=QueryMsg.substring(0, 10);
				String Msg=QueryMsg.substring(10);
				QueryMsg=tpdu+header+Msg;
			}
			wf.log("响应包:长度 " + QueryMsg.length() / 2 + " 数据 "+ QueryMsg, "调试");
			if ((!QueryMsg.equals("-1")) && (!QueryMsg.equals(""))) {
				QueryMsg = "0"+ Package64.UnPackage(PackageUtil.hexStringToByte(QueryMsg), "39,54",wf);
			} else {
				return "-1_";
			}
			wf.log("佘额查询返回数据:" + QueryMsg, "调试");
			return QueryMsg;
		}catch(Exception e){
			throw e;
		}
	}
	/**
	 * 帐单费用缴费（交易）
	 * @param trk2 二磁道数据
	 * @param trk3 三磁道数据
	 * @param pin 密码
	 * @param money 交易金额
	 * @param accountNumber 卡号
	 * @param serialNumber 订单号
	 * @param bit23 IC卡序列号
	 * @param bit55 IC卡 55 域
	 * @param bit14 IC卡 序列号
	 * @return 返回消费相关信息
	 * @throws Exception
	 */
	public String BillPayment(String trk2, String trk3, String pin,String money,String accountNumber,String serialNumber,String bit23,String bit55,String bit14) throws Exception {
		try{
			String des_pin=TestDes.MakeDesPin(accountNumber, pin, PinKey,MasterKey);
			
			String QueryMsg = "";
			String TYPE_ID = "0200";
			Package64 pk = new Package64();
			pk.setTpdu(PackageUtil.hexStringToByte(this.tpdu));
			pk.setHeader(PackageUtil.hexStringToByte(""));
			pk.setMessagetype(PackageUtil.hexStringToByte(TYPE_ID));
			wf.log("-------------------请求包域值信息-------------------",	"调试");
			wf.log("[tpdu]=" + this.tpdu, "调试");
			wf.log("[header]=" + this.header, "调试");
			wf.log("[messagetype]=" + TYPE_ID, "调试");
			// 3、4、11、22、25、26、35、36、41、42、49、52、53、61、64
			String str = "bit3,bit4,bit11,bit22,bit25,bit26,bit35,bit36,bit41,bit42,bit49,bit52,bit53,bit61,bit64";
			String temp52=",bit52";
			String temp35 = ",bit35";
			String temp36 = ",bit36";
			String temp23=",bit23";
			String temp55=",bit55";
			String temp14=",bit14";
			//String Pan="";
			if ("".equals(trk2.trim())) {
				temp35 = "";
			}else{
				//Pan=trk2.split("d")[0];
				trk2=DesUtil.newEncryptStanderTranck(trkKey, trk2).substring(2);
			}
			if ("".equals(trk3.trim())) {
				temp36 = "";
			}else{
				trk3=DesUtil.newEncryptStanderTranck(trkKey, trk3).substring(2);
			}
			if("".equals(des_pin.trim()))
			{
				temp52="";
			}
			if("".equals(bit23.trim()))
			{
				temp23="";
			}
			if("".equals(bit55.trim()))
			{
				temp55="";
			}
			if("".equals(bit14.trim()))
			{
				temp14="";
			}
			str="bit2,bit3,bit4,bit11,bit12,bit13"+temp14+",bit22"+temp23+",bit25,bit26,bit32"+temp35+temp36+",bit41,bit42,bit49"+temp52+",bit53"+temp55+",bit60,bit62,bit63,bit64";
			for (String one : str.split(",")) {
				Field filed = (Field) act.getBean(one);
				if (one.equals("bit2")) {
					filed.valueof(accountNumber);
				}else if (one.equals("bit3")) {
					filed.valueof("001111");
				} else if (one.equals("bit4")) {
					filed.valueof(money);
				} else if (one.equals("bit11")) {
					filed.valueof(serialNumber);
				}else if (one.equals("bit12")) {
					filed.valueof(TimeUtils.getNowDateTime("HHmmss"));
				}else if (one.equals("bit13")) {
					filed.valueof(TimeUtils.getNowDateTime("MMdd"));
				} else if (one.equals("bit14")) {
					filed.valueof(bit14);
				} else if (one.equals("bit22")) {
					if("".equals(bit55.trim()))
					{
						filed.valueof("021");
					}else{
						filed.valueof("051");
					}
				} else if (one.equals("bit23")) {
					filed.valueof(bit23);
				} else if (one.equals("bit25")) {
					filed.valueof("00");
				} else if (one.equals("bit26")) {
					filed.valueof("06");
				} else if (one.equals("bit32")) {
					filed.valueof(bit32);
				} else if (one.equals("bit35")) {
					filed.valueof(trk2);
				} else if (one.equals("bit36")) {
					filed.valueof(trk3);
				} else if (one.equals("bit41")) {
					filed.valueof(this.PosNo);
				} else if (one.equals("bit42")) {
					filed.valueof(this.ShopCode);
				} else if (one.equals("bit49")) {
					filed.valueof("156");
				} else if (one.equals("bit52")) {
					byte[] tmp = PackageUtil.hexStringToByte(des_pin);
					filed.valueof(tmp);
				} else if (one.equals("bit53")) {
					filed.valueof("2600000000000000");
				} else if (one.equals("bit55")) {
					filed.valueof(bit55);
				} else if (one.equals("bit60")) {
					if("".equals(bit55.trim()))
					{
						filed.valueof("22" + this.batch);
					}else{
						filed.valueof("22" + this.batch+"00050");
					}
				}else if (one.equals("bit62")) {
					filed.setType(Field.Type.ASCII);//############
	//				filed.valueof(PackageUtil.getCnASCII(bit62));
					filed.valueof(bit62);
				} else if (one.equals("bit63")) {
					filed.valueof(PackageUtil.getCnASCII(this.operator));
				} else if (one.equals("bit64")) {
					byte[] tmp = PackageUtil.hexStringToByte("3335344331393934");
					filed.valueof(tmp);
				}
				pk.getData().put(filed.getFiledNumber(), filed);
			}
			pk.setBitmap(Package64.CreateBitMap(pk.getData().keySet()));
	
			String tranMsg = PackageUtil.byte2hex(pk.getMessagetype())
					+ PackageUtil.byte2hex(pk.getBitmap());
			for (Integer one : pk.getData().keySet()) {
				if (one != 64) {
					String bitval = PackageUtil.byte2hex(pk.getData().get(one).toByte());
					tranMsg += bitval;
					wf.log("bit" + one + ":" + bitval, "调试");
				}
			}
			// System.out.println("tranMsg:" + tranMsg);
	
			String macstr="";
			macstr=TestDes.MakeECBMac(MacKey, tranMsg,MasterKey);
			wf.log("bit64:" + macstr, "调试");
			// System.out.println("mac:" + macstr);
			Field filed = (Field) act.getBean("bit64");
			byte[] tmp = PackageUtil.hexStringToByte(macstr);
			filed.valueof(tmp);
			pk.getData().put(filed.getFiledNumber(), filed);
	
			byte[] pk_byteArray = pk.package64();
			ByteBuffer buff = ByteBuffer.allocate(pk_byteArray.length + 2);
			// System.out.println("pk_byteArray length: " + pk_byteArray.length);
			buff.putShort((short) pk_byteArray.length);
			buff.put(pk_byteArray);
			// System.out.println(PackageUtil.byte2hex(buff.array()));
	
			wf.log("----------------------------------------------------", "调试");
			wf.log("请求包:长度 " + pk_byteArray.length + " 数据 "+ PackageUtil.byte2hex(buff.array()), "调试");
			wf.log("", "调试");
            System.out.println("EBC收款请求报文：" + PackageUtil.byte2hex(buff.array()));
			QueryMsg = detection(buff.array());
            System.out.println("EBC收款响应报文："+QueryMsg);
            if ((!QueryMsg.equals("-1")) && (!QueryMsg.equals("")))
			{
				String tpdu=QueryMsg.substring(0, 10);
				String Msg=QueryMsg.substring(10);
				QueryMsg=tpdu+header+Msg;
			}
			wf.log("响应包:长度 " + QueryMsg.length() / 2 + " 数据 "+ QueryMsg, "调试");
			if ((!QueryMsg.equals("-1")) && (!QueryMsg.equals(""))) {
				QueryMsg = "0"+ Package64.UnPackage(PackageUtil.hexStringToByte(QueryMsg),"2,4,11,12,13,14,37,38,39",wf);
			} else {
				return "-1_";
			}
			wf.log("帐单费用缴费返回数据:" + QueryMsg, "调试");
			return QueryMsg;
		}catch(Exception e){
			throw e;
		}
	}

	/**
	 * 帐单缴费冲正（交易）
	 * 
	 * @param trk2
	 *            二磁道数据
	 * @param trk3
	 *            三磁道数据
	 * @param des_pin
	 *            卡交易密码
	 * @param money
	 *            交易金额
	 * @param bit61
	 *            61域数据      
	 * @param bit62
	 *            62域数据      
	 * 
	 * @return 订单信息
	 * @throws Exception
	 */
	public String unBillPayment(String trk2, String trk3,String money,String accountNumber,String serialNumber,String bit37,String bit38,String bit23,String bit55,String bit14) throws Exception {
		try{
			String QueryMsg = "";
			String TYPE_ID = "0400";
			//this.serialNumber = unAddSerialNumber(this.serialNumber);
			Package64 pk = new Package64();
			pk.setTpdu(PackageUtil.hexStringToByte(this.tpdu));
			pk.setHeader(PackageUtil.hexStringToByte(""));
			pk.setMessagetype(PackageUtil.hexStringToByte(TYPE_ID));
			wf.log("-------------------请求包域值信息-------------------","调试");
			wf.log("[tpdu]=" + this.tpdu, "调试");
			wf.log("[header]=" + this.header, "调试");
			wf.log("[messagetype]=" + TYPE_ID, "调试");
			// 冲正39域为冲正原因,取值如下:
			/*
			 * 98 POS终端在时限内未能收到POS中心的应答 96 POS终端收到POS中心的批准应答消息，但由于POS机故障无法完成交易 A0
			 * POS终端对收到POS中心的批准应答消息，验证MAC出错 06 其他情况引发的冲正
			 */
			String str = "bit3,bit4,bit11,bit22,bit25,bit35,bit36,bit38,bit39,bit41,bit42,bit49,bit61,bit62,bit64";
	//		String temp35=",bit35";
	//		String temp36=",bit36";
	//		String temp37 = ",bit37";
			String temp38 = ",bit38";
			
			String temp23 = ",bit23";
			String temp55 = ",bit55";
			String temp14 = ",bit14";
			//String PAN="";
			if(!"".equals(trk2))
			{
				trk2=DesUtil.newEncryptStanderTranck(trkKey, trk2).substring(2);
			}
			if(!"".equals(trk3))
			{
				trk3=DesUtil.newEncryptStanderTranck(trkKey, trk3).substring(2);
			}
			
			if("".equals(bit38))
			{
				temp38="";
			}
			if("".equals(bit23))
			{
				temp23="";
			}
			if("".equals(bit55))
			{
				temp55="";
			}
			if("".equals(bit14))
			{
				temp14="";
			}
			str="bit2,bit3,bit4,bit11"+temp14+",bit22"+temp23+",bit25,bit35,bit36"+temp38+",bit39,bit41,bit42,bit49"+temp55+",bit60,bit62,bit63,bit64";
			for (String one : str.split(",")) {
				Field filed = (Field) act.getBean(one);
				if (one.equals("bit2")) {
					filed.valueof(accountNumber);
				} else if (one.equals("bit3")) {
					filed.valueof("001111");
				} else if (one.equals("bit4")) {
					filed.valueof(money);
				} else if (one.equals("bit11")) {
					filed.valueof(serialNumber);
				} else if (one.equals("bit14")) {
					filed.valueof(bit14);
				} else if (one.equals("bit22")) {
					if("".equals(bit55.trim()))
					{
						filed.valueof("021");
					}else{
						filed.valueof("051");
					}
				} else if (one.equals("bit23")) {
					filed.valueof(bit23);
				} else if (one.equals("bit25")) {
					filed.valueof("00");
				} else if (one.equals("bit35")) {
					filed.valueof(trk2);
				} else if (one.equals("bit36")) {
					filed.valueof(trk3);
				} else if (one.equals("bit37")) {
					filed.valueof(bit37);
				} else if (one.equals("bit38")) {
					filed.valueof(bit38);
				} else if (one.equals("bit39")) {
					filed.valueof("06");
				} else if (one.equals("bit41")) {
					filed.valueof(this.PosNo);
				} else if (one.equals("bit42")) {
					filed.valueof(this.ShopCode);
				} else if (one.equals("bit49")) {
					filed.valueof("156");
				} else if (one.equals("bit55")) {
					filed.valueof(bit55);
				} else if (one.equals("bit60")) {
					if("".equals(bit55.trim()))
					{
						filed.valueof("22" + this.batch);
					}else{
						filed.valueof("22" + this.batch+"00050");
					}
				}else if (one.equals("bit62")) {
					filed.setType(Field.Type.ASCII);//############
					filed.valueof(bit62);
				} else if (one.equals("bit63")) {
					filed.valueof(PackageUtil.getCnASCII(this.operator));
				} else if (one.equals("bit64")) {
					byte[] tmp = PackageUtil.hexStringToByte("0000000000000000");
					filed.valueof(tmp);
				}
				pk.getData().put(filed.getFiledNumber(), filed);
			}
			pk.setBitmap(Package64.CreateBitMap(pk.getData().keySet()));
	
			String tranMsg = PackageUtil.byte2hex(pk.getMessagetype())
					+ PackageUtil.byte2hex(pk.getBitmap());
			for (Integer one : pk.getData().keySet()) {
				if (one != 64) {
					String bitval = PackageUtil.byte2hex(pk.getData().get(one)
							.toByte());
					tranMsg += bitval;
					wf.log("bit" + one + ":" + bitval, "调试");
				}
			}
			System.out.println("tranMsg:" + tranMsg);
	
			String macstr="";
			macstr=TestDes.MakeECBMac(MacKey, tranMsg,MasterKey);
			wf.log("bit64:" + macstr, "调试");
			// System.out.println("mac:" + macstr);
			Field filed = (Field) act.getBean("bit64");
			byte[] tmp = PackageUtil.hexStringToByte(macstr);
			filed.valueof(tmp);
			pk.getData().put(filed.getFiledNumber(), filed);
	
			byte[] pk_byteArray = pk.package64();
			ByteBuffer buff = ByteBuffer.allocate(pk_byteArray.length + 2);
			// System.out.println("pk_byteArray length: " + pk_byteArray.length);
			buff.putShort((short) pk_byteArray.length);
			buff.put(pk_byteArray);
			// System.out.println(PackageUtil.byte2hex(buff.array()));
			wf.log(				"----------------------------------------------------", "调试");
			wf.log("请求包:长度 " + pk_byteArray.length + " 数据 "	+ PackageUtil.byte2hex(buff.array()), "调试");
			wf.log("", "调试");
			
			QueryMsg = detection(buff.array());
			if ((!QueryMsg.equals("-1")) && (!QueryMsg.equals("")))
			{
				String tpdu=QueryMsg.substring(0, 10);
				String Msg=QueryMsg.substring(10);
				QueryMsg=tpdu+header+Msg;
			}
			wf.log("响应包:长度 " + QueryMsg.length() / 2 + " 数据 "+ QueryMsg, "调试");
			if ((!QueryMsg.equals("-1")) && (!QueryMsg.equals(""))) {
				QueryMsg = "0"+ Package64.UnPackage(PackageUtil.hexStringToByte(QueryMsg),"2,4,11,12,13,14,37,38,39,44,61",wf);
			} else {
				return "-1_";
			}
			wf.log("帐单缴费冲正返回数据:" + QueryMsg, "调试");
			return QueryMsg;
		}catch(Exception e){
			throw e;
		}
	}
	/**
	 * 帐单缴费冲正（交易）
	 * 
	 * @param trk2
	 *            二磁道数据
	 * @param trk3
	 *            三磁道数据
	 * @param des_pin
	 *            卡交易密码
	 * @param money
	 *            交易金额
	 * @param bit61
	 *            61域数据      
	 * @param bit62
	 *            62域数据      
	 * 
	 * @return 订单信息
	 * @throws Exception
	 */
	public String undoBillPayment(String trk2, String trk3, String pin,String money,String accountNumber,String serialNumber,String bit37,String bit38,String serialNumber2,String bit23,String bit55,String bit14) throws Exception {
		try{
			String des_pin=TestDes.MakeDesPin(accountNumber, pin, PinKey,MasterKey);
			
			String QueryMsg = "";
			String TYPE_ID = "0200";
			//this.serialNumber = unAddSerialNumber(this.serialNumber);
			Package64 pk = new Package64();
			pk.setTpdu(PackageUtil.hexStringToByte(this.tpdu));
			pk.setHeader(PackageUtil.hexStringToByte(""));
			pk.setMessagetype(PackageUtil.hexStringToByte(TYPE_ID));
			wf.log("-------------------请求包域值信息-------------------","调试");
			wf.log("[tpdu]=" + this.tpdu, "调试");
			wf.log("[header]=" + this.header, "调试");
			wf.log("[messagetype]=" + TYPE_ID, "调试");
			// 冲正39域为冲正原因,取值如下:
			/*
			 * 98 POS终端在时限内未能收到POS中心的应答 96 POS终端收到POS中心的批准应答消息，但由于POS机故障无法完成交易 A0
			 * POS终端对收到POS中心的批准应答消息，验证MAC出错 06 其他情况引发的冲正
			 */
			String str = "bit3,bit4,bit11,bit22,bit25,bit26,bit35,bit36,bit38,bit39,bit41,bit42,bit49,bit61,bit62,bit64";
			String temp35=",bit35";
			String temp36=",bit36";
			String temp37 = ",bit37";
			String temp38 = ",bit38";
			
			String temp23 = ",bit23";
			String temp55 = ",bit55";
			String temp14 = ",bit14";
			if("".equals(trk2))
			{
				temp35="";
			}else{
				trk2=DesUtil.newEncryptStanderTranck(trkKey, trk2).substring(2);
			}
			if("".equals(trk3))
			{
				temp36="";
			}else{
				trk3=DesUtil.newEncryptStanderTranck(trkKey, trk3).substring(2);
			}
			if("".equals(bit37))
			{
				temp37="";
			}
			if("".equals(bit38))
			{
				temp38="";
			}
			if("".equals(bit23))
			{
				temp23="";
			}
			if("".equals(bit55))
			{
				temp55="";
			}
			if("".equals(bit14))
			{
				temp14="";
			}
			str="bit2,bit3,bit4,bit11"+temp14+",bit22"+temp23+",bit25,bit26"+temp35+temp36+temp37+temp38+",bit41,bit42,bit49,bit52,bit53"+temp55+",bit60,bit61,bit62,bit63,bit64";
			for (String one : str.split(",")) {
				Field filed = (Field) act.getBean(one);
				if (one.equals("bit2")) {
					filed.valueof(accountNumber);
				}else if (one.equals("bit3")) {
					filed.valueof("201111");
				} else if (one.equals("bit4")) {
					filed.valueof(money);
				} else if (one.equals("bit11")) {
					filed.valueof(serialNumber);
				} else if (one.equals("bit14")) {
					filed.valueof(bit14);
				} else if (one.equals("bit22")) {
					if("".equals(bit55.trim()))
					{
						filed.valueof("021");
					}else{
						filed.valueof("051");
					}
				} else if (one.equals("bit23")) {
					filed.valueof(bit23);
				} else if (one.equals("bit25")) {
					filed.valueof("00");
				} else if (one.equals("bit26")) {
					filed.valueof("06");
				} else if (one.equals("bit35")) {
					filed.valueof(trk2);
				} else if (one.equals("bit36")) {
					filed.valueof(trk3);
				} else if (one.equals("bit37")) {
					filed.valueof(bit37);
				} else if (one.equals("bit38")) {
					filed.valueof(bit38);
				} else if (one.equals("bit41")) {
					filed.valueof(this.PosNo);
				} else if (one.equals("bit42")) {
					filed.valueof(this.ShopCode);
				} else if (one.equals("bit49")) {
					filed.valueof("156");
				} else if (one.equals("bit52")) {
					byte[] tmp = PackageUtil.hexStringToByte(des_pin);
					filed.valueof(tmp);
				} else if (one.equals("bit53")) {
					filed.valueof("2600000000000000");
				} else if (one.equals("bit55")) {
					filed.valueof(bit55);
				} else if (one.equals("bit60")) {
					if("".equals(bit55.trim()))
					{
						filed.valueof("23" + this.batch);
					}else{
						filed.valueof("23" + this.batch+"00050");
					}
				} else if (one.equals("bit61")) {
					filed.valueof(this.batch+serialNumber2);
				}else if (one.equals("bit62")) {
					filed.setType(Field.Type.ASCII);//############
					filed.valueof(bit62);
				} else if (one.equals("bit63")) {
					filed.valueof(PackageUtil.getCnASCII(this.operator));
				}  else if (one.equals("bit64")) {
					byte[] tmp = PackageUtil.hexStringToByte("0000000000000000");
					filed.valueof(tmp);
				}
				pk.getData().put(filed.getFiledNumber(), filed);
			}
			pk.setBitmap(Package64.CreateBitMap(pk.getData().keySet()));
	
			String tranMsg = PackageUtil.byte2hex(pk.getMessagetype())
					+ PackageUtil.byte2hex(pk.getBitmap());
			for (Integer one : pk.getData().keySet()) {
				if (one != 64) {
					String bitval = PackageUtil.byte2hex(pk.getData().get(one)
							.toByte());
					tranMsg += bitval;
					wf.log("bit" + one + ":" + bitval, "调试");
				}
			}
			System.out.println("tranMsg:" + tranMsg);
	
			String macstr="";
			macstr=TestDes.MakeECBMac(MacKey, tranMsg,MasterKey);
			wf.log("bit64:" + macstr, "调试");
			// System.out.println("mac:" + macstr);
			Field filed = (Field) act.getBean("bit64");
			byte[] tmp = PackageUtil.hexStringToByte(macstr);
			filed.valueof(tmp);
			pk.getData().put(filed.getFiledNumber(), filed);
	
			byte[] pk_byteArray = pk.package64();
			ByteBuffer buff = ByteBuffer.allocate(pk_byteArray.length + 2);
			// System.out.println("pk_byteArray length: " + pk_byteArray.length);
			buff.putShort((short) pk_byteArray.length);
			buff.put(pk_byteArray);
			// System.out.println(PackageUtil.byte2hex(buff.array()));
			wf.log(				"----------------------------------------------------", "调试");
			wf.log("请求包:长度 " + pk_byteArray.length + " 数据 "	+ PackageUtil.byte2hex(buff.array()), "调试");
			wf.log("", "调试");
			
			QueryMsg = detection(buff.array());
			if ((!QueryMsg.equals("-1")) && (!QueryMsg.equals("")))
			{
				String tpdu=QueryMsg.substring(0, 10);
				String Msg=QueryMsg.substring(10);
				QueryMsg=tpdu+header+Msg;
			}
			wf.log("响应包:长度 " + QueryMsg.length() / 2 + " 数据 "+ QueryMsg, "调试");
			if ((!QueryMsg.equals("-1")) && (!QueryMsg.equals(""))) {
				QueryMsg = "0"+ Package64.UnPackage(PackageUtil.hexStringToByte(QueryMsg),"2,4,11,12,13,14,37,38,39,44,61",wf);
			} else {
				return "-1_";
			}
			wf.log("帐单缴费冲正返回数据:" + QueryMsg, "调试");
			return QueryMsg;
		}catch(Exception e){
			throw e;
		}
	}
	/**
	 * IC卡传输密钥下载
	 * 
	 * @return 工作密钥
	 * @throws Exception
	 */
	public String ICTransKeyDown(String ICID,String ICNo) throws Exception {
		try{
			String LoginMsg = "0";
			String TYPE_ID = "0800";
			wf.log("-------------------请求包域值信息-------------------",	"调试");
			Package64 pk = new Package64();
			pk.setTpdu(PackageUtil.hexStringToByte(this.tpdu));
			pk.setHeader(PackageUtil.hexStringToByte(this.header));
			pk.setMessagetype(PackageUtil.hexStringToByte(TYPE_ID));
			wf.log("[tpdu]=" + this.tpdu, "调试");
			wf.log("[header]=" + this.header, "调试");
			wf.log("[messagetype]=" + TYPE_ID, "调试");
			// 11、41、42、60、63
			String str = "bit3,bit34";
			for (String one : str.split(",")) {
				Field filed = (Field) act.getBean(one);
				if (one.equals("bit3")) {
					filed.valueof("900000");
				} else if (one.equals("bit34")) {
					filed.valueof(ICID + ICNo);
				}
				pk.getData().put(filed.getFiledNumber(), filed);
			}
			this.bitmap = Package64.CreateBitMap(pk.getData().keySet());
			wf.log("[bitmap]=" + PackageUtil.byte2hex(this.bitmap),"调试");
			for (Integer one : pk.getData().keySet()) {
				wf.log("bit" + one + ":"+ PackageUtil.byte2hex(pk.getData().get(one).toByte()),"调试");
			}
			wf.log("----------------------------------------------------", "调试");
			pk.setBitmap(this.bitmap);
			byte[] pk_byteArray = pk.package64();
			ByteBuffer buff = ByteBuffer.allocate(pk_byteArray.length + 2);
			buff.putShort((short) pk_byteArray.length);
			buff.put(pk_byteArray);
	
	
			wf.log("请求包:长度 " + pk_byteArray.length + " 数据 "	+ PackageUtil.byte2hex(buff.array()), "调试");
			wf.log("", "调试");
			LoginMsg = detection(buff.array());
			wf.log("响应包:长度 " + LoginMsg.length() / 2 + " 数据 "+ LoginMsg, "调试");
			if ((!LoginMsg.equals("-1")) && (!LoginMsg.equals(""))) {
				LoginMsg = "0"+ Package64.UnPackage(PackageUtil.hexStringToByte(LoginMsg), "39,62",wf);
			} else {
				return "-1_";
			}
			wf.log("银联签到返回数据:" + LoginMsg, "调试");
			return LoginMsg;
		}catch(Exception e){
			throw e;
		}
	}
	/**
	 * POS状态上送
	 * 
	 * @param	ParmType
	 * 				参数下载类别
	 * 					磁条卡交易采用362；
	 * 					IC卡公钥下载交易采用372；
	 * 					IC卡参数下载交易采用382
	 * 
	 * @return 批次号
	 * @throws Exception
	 */
	public String POSStatuUP(String ParmType) throws Exception {
		try{
			String LoginMsg = "0";
			String TYPE_ID = "0820";
			wf.log("-------------------请求包域值信息-------------------",	"调试");
			Package64 pk = new Package64();
			pk.setTpdu(PackageUtil.hexStringToByte(this.tpdu));
			pk.setHeader(PackageUtil.hexStringToByte(this.header));
			pk.setMessagetype(PackageUtil.hexStringToByte(TYPE_ID));
			wf.log("[tpdu]=" + this.tpdu, "调试");
			wf.log("[header]=" + this.header, "调试");
			wf.log("[messagetype]=" + TYPE_ID, "调试");
			// 11、41、42、60、63
			String str = "bit41,bit42,bit60,bit62";
			for (String one : str.split(",")) {
				Field filed = (Field) act.getBean(one);
				if (one.equals("bit41")) {
					filed.valueof(this.PosNo);
				}else if (one.equals("bit42")) {
					filed.valueof(this.ShopCode);
				} else if (one.equals("bit60")) {
					filed.valueof("00" + this.batch + ParmType);
				} else if (one.equals("bit62")) {
					filed.valueof(PackageUtil.getCnASCII("100"));
				} 
				pk.getData().put(filed.getFiledNumber(), filed);
			}
			this.bitmap = Package64.CreateBitMap(pk.getData().keySet());
			wf.log("[bitmap]=" + PackageUtil.byte2hex(this.bitmap),"调试");
			for (Integer one : pk.getData().keySet()) {
				wf.log("bit" + one + ":"+ PackageUtil.byte2hex(pk.getData().get(one).toByte()),"调试");
			}
			wf.log("----------------------------------------------------", "调试");
			pk.setBitmap(this.bitmap);
			byte[] pk_byteArray = pk.package64();
			ByteBuffer buff = ByteBuffer.allocate(pk_byteArray.length + 2);
			buff.putShort((short) pk_byteArray.length);
			buff.put(pk_byteArray);
	
	
			wf.log("请求包:长度 " + pk_byteArray.length + " 数据 "	+ PackageUtil.byte2hex(buff.array()), "调试");
			wf.log("", "调试");
			LoginMsg = detection(buff.array());
			wf.log("响应包:长度 " + LoginMsg.length() / 2 + " 数据 "+ LoginMsg, "调试");
			if ((!LoginMsg.equals("-1")) && (!LoginMsg.equals(""))) {
				LoginMsg = "0"+ Package64.UnPackage(PackageUtil.hexStringToByte(LoginMsg), "39,62",wf);
			} else {
				return "-1_";
			}
			wf.log("银联签到返回数据:" + LoginMsg, "调试");
			return LoginMsg;
		}catch(Exception e){
			throw e;
		}
	}
	/**
	 * POS参数传递
	 * 
	 * @param	ParmType
	 * 				参数下载类别
	 *					磁条卡交易采用360/361
	 * 					IC卡公钥下载交易采用370/371;
	 *					IC卡参数下载交易采用380/381;
	 *					TMS参数下载结束采用364/365;
	 *					卡BIN黑名单下载结束采用390/391
	 * @return 批次号
	 * @throws Exception
	 */
	public String POSICParmKeyDown(String ParmType,String RIDParm) throws Exception {
		try{
			String LoginMsg = "0";
			String TYPE_ID = "0800";
			wf.log("-------------------请求包域值信息-------------------",	"调试");
			Package64 pk = new Package64();
			pk.setTpdu(PackageUtil.hexStringToByte(this.tpdu));
			pk.setHeader(PackageUtil.hexStringToByte(this.header));
			pk.setMessagetype(PackageUtil.hexStringToByte(TYPE_ID));
			wf.log("[tpdu]=" + this.tpdu, "调试");
			wf.log("[header]=" + this.header, "调试");
			wf.log("[messagetype]=" + TYPE_ID, "调试");
			// 11、41、42、60、63
			String str = "bit41,bit42,bit60,bit62";
			for (String one : str.split(",")) {
				Field filed = (Field) act.getBean(one);
				if (one.equals("bit41")) {
					filed.valueof(this.PosNo);
				}else if (one.equals("bit42")) {
					filed.valueof(this.ShopCode);
				} else if (one.equals("bit60")) {
					filed.valueof("00" + this.batch + ParmType);
				} else if (one.equals("bit62")) {
					filed.valueof(RIDParm);
				} 
				pk.getData().put(filed.getFiledNumber(), filed);
			}
			this.bitmap = Package64.CreateBitMap(pk.getData().keySet());
			wf.log("[bitmap]=" + PackageUtil.byte2hex(this.bitmap),"调试");
			for (Integer one : pk.getData().keySet()) {
				wf.log("bit" + one + ":"+ PackageUtil.byte2hex(pk.getData().get(one).toByte()),"调试");
			}
			wf.log("----------------------------------------------------", "调试");
			pk.setBitmap(this.bitmap);
			byte[] pk_byteArray = pk.package64();
			ByteBuffer buff = ByteBuffer.allocate(pk_byteArray.length + 2);
			buff.putShort((short) pk_byteArray.length);
			buff.put(pk_byteArray);
	
	
			wf.log("请求包:长度 " + pk_byteArray.length + " 数据 "	+ PackageUtil.byte2hex(buff.array()), "调试");
			wf.log("", "调试");
			LoginMsg = detection(buff.array());
			wf.log("响应包:长度 " + LoginMsg.length() / 2 + " 数据 "+ LoginMsg, "调试");
			if ((!LoginMsg.equals("-1")) && (!LoginMsg.equals(""))) {
				LoginMsg = "0"+ Package64.UnPackage(PackageUtil.hexStringToByte(LoginMsg), "39,62",wf);
			} else {
				return "-1_";
			}
			wf.log("银联签到返回数据:" + LoginMsg, "调试");
			return LoginMsg;
		}catch(Exception e){
			throw e;
		}
	}
	
//	public static void main(String[] args) throws Exception {
//		
////		EBCSocketToBoss st = new EBCSocketToBoss("600000000000001","11111111","000032","44444444444444444444444444444444","4364037F5FFAEB71183EB4EE7A4949D5","B63DAAD67BAB18672FD80F9859AF9DF1","17214B266A2637FAC87E2461D6B93A9E");
//		//EBCSocketToBoss st = new EBCSocketToBoss("310003903001830","90001964","000001","BC317706FD70751AFE42CA5080A9F6D5","4BD44649015DF44E47738AA8CCEA4703","3A72E9B5E7D9BFEB1AAC7A25C91DCC30","D54EC9968A4F6CFD83E927863532CA84");
//		
//		EBCSocketToBoss st = new EBCSocketToBoss("310310559989817","01072702","000002","34247633133747332343376336434479","79184404B12DA1EC986C050A51ECA8A4","0033075C18981AA485E1E0416C8AE772","529CE5D29D86478DDE69533C04578A3E");
//		//EBCSocketToBoss st = new EBCSocketToBoss("310310559989816","01072701","000002","09211776993340307712433209634615","FFB112BBEEBD733AAB2775D9FD0D0AD5","BA20F7C89908D66D7F80137B15D4E0FA","C5C050FA5942319756EA859CBF1297C4");
//		//7CE52F9B87C25885DA7C2E5F81B898A8_2056D91F40A96931F37AA7178BEE67C0_89DF0517C7B1FDA41B9B0653287B7CBB
////		EBCSocketToBoss st = new EBCSocketToBoss("310310541120161","01072679","000003","86677553698320736522029923273253","7CE52F9B87C25885DA7C2E5F81B898A8","2056D91F40A96931F37AA7178BEE67C0","89DF0517C7B1FDA41B9B0653287B7CBB");
//		String serialNumber = "002007";
//		String accountNumber = "6259960005135454";
//		String trk2 = "6259960005135454d21032011442713500000";
//		String trk3 = "";
//		//trk2="6217900100000371909d22092201000065500";
//		trk2="6210300016512078d49121206307260000000"; //北京银行
//		String Pin="147258";
//		
//		//0_6210300016512078_000000000001_002004_181331_0514_ _181331647355_ _00
//		//交易金额
//		String money = "000000000001";
//		String bit37="183721652178";
//		String bit38="";
//		String serialNumber2="002005";
//		//IC卡的ID号(32长度,长度不足后补空格)
//		String ICID="";
//		//IC卡编号(4长度,长度不足前补0)
//		String ICNo="";
//		//参数下载类别
//		//		磁条卡交易采用360/361
//		// 		IC卡公钥下载交易采用370/371;
//		//		IC卡参数下载交易采用380/381;
//		//		TMS参数下载结束采用364/365;
//		//		卡BIN黑名单下载结束采用390/391
//		String ParmType="370";
//		String bit23="";
//		String bit55="";
//		String bit14="";
//		//st.serialNumber="200028";
//		//String masKey="AA17070598B13C472F4C502D13F4D6CB";
//		//masKey=DesUtil.decode3DES(masKey,st.MPOSKey);
//		//System.out.println("masKey:"+masKey);
////		System.out.println("终端签到,返回:" + st.Login0800(serialNumber));
////		System.out.println("银行卡余额查询,返回:" + st.Query(trk2, trk3, Pin,accountNumber,serialNumber,bit23,bit55,bit14));
////		System.out.println("消费,返回:" + st.BillPayment(trk2, trk3, Pin, money,accountNumber,serialNumber,bit23,bit55,bit14));
////		System.out.println("冲正,返回:" +st.unBillPayment(trk2, trk3,money,accountNumber,serialNumber, bit37, bit38,bit23,bit55,bit14));	
////		System.out.println("消费撤消,返回:"+st.undoBillPayment(trk2, trk3, Pin, money,accountNumber, serialNumber,bit37, bit38, serialNumber2,bit23,bit55,bit14));
//		//System.out.println("IC卡传输密钥下载,返回:"+st.ICTransKeyDown(ICID, ICNo));
//		//需要下载的公钥RID和索引，采用TLV格式，每次只能请求一组公钥
//		//String RIDParm="9F0605A0000003339F220108";
//		//System.out.println("POS参数下载,返回:"+st.POSICParmKeyDown(ParmType,RIDParm));
//		
//		//磁条卡交易采用362；
//		//IC卡公钥下载交易采用372；
//		//IC卡参数下载交易采用382
//		String ParmType2="382";
//		//System.out.println("POS状态上送,返回:"+st.POSStatuUP(ParmType2));
//	}
}